home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / CRS / crs54.d81 / sgtool15.lzh / DEMO.C < prev    next >
Text File  |  2009-10-10  |  17KB  |  700 lines

  1. /*
  2. SG C Tools 1.5
  3.  
  4. (C) 1993 Steve Goldsmith
  5. All Rights Reserved
  6.  
  7. SG C Tools Demo shows how to use most of the features available with SG C
  8. Tools.
  9.  
  10. Compiled with HI-TECH C 3.09 (CP/M-80).
  11.  
  12. To compile with HI-TECH C and SG C Tools source on same disk use:
  13. C DEMO.C -LC128
  14. */
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <ctype.h>
  19. #include <conio.h>
  20. #include <sys.h>
  21. #include <stat.h>
  22. #include <cpm.h>
  23. #include <hitech.h>
  24. #include <vdc.h>
  25. #include <cia.h>
  26. #include <sid.h>
  27. #include <pcx.h>
  28.  
  29. /* 64k vdc locations */
  30.  
  31. #define appBitMapMem 0x4000
  32. #define appAttrMem   0x0800
  33.  
  34. /* colors used by this app */
  35.  
  36. #define appClockCo     vdcAltChrSet+vdcRvsVid+vdcLightCyan
  37. #define appMenuScrCo   vdcBlack
  38. #define appDeskCo      vdcAltChrSet+vdcMediumGray
  39. #define appMenuTxtCo   vdcAltChrSet+vdcLightCyan
  40. #define appMenuWinCo   vdcAltChrSet+vdcLightBlue
  41. #define appIScrCo      vdcBlack
  42. #define appIDeskCo     vdcAltChrSet+vdcMediumGray
  43. #define appIWinTxtCo   vdcAltChrSet+vdcDarkBlue
  44. #define appIWinCo      vdcAltChrSet+vdcDarkBlue
  45. #define appGrTextCo    (vdcDarkGray << 4) | vdcWhite
  46. #define appSoundWinCo  vdcAltChrSet+vdcWhite
  47. #define appSoundTxt1Co vdcAltChrSet+vdcLightGreen+vdcBlink
  48. #define appSoundTxt2Co vdcAltChrSet+vdcDarkGreen
  49. #define appCtrlTxt1Co  vdcAltChrSet+vdcRvsVid+vdcLightYellow
  50. #define appCtrlTxt2Co  vdcAltChrSet+vdcWhite
  51. #define appCtrlWinCo   vdcAltChrSet+vdcLightCyan
  52.  
  53. extern uchar     vdcScrHorz;
  54. extern ushort    vdcDispMem;
  55. extern ushort    vdcAttrMem;
  56. extern ushort    vdcCharMem;
  57. extern ushort    vdcCharMemSize;
  58. extern ushort    vdcBitMapMemSize;
  59.  
  60. extern uchar     sidPot1X;
  61. extern uchar     sidPot1Y;
  62. extern uchar     sidPot2X;
  63. extern uchar     sidPot2Y;
  64. extern uchar     sidMouse1X;
  65. extern uchar     sidMouse1Y;
  66. extern uchar     sidMouse2X;
  67. extern uchar     sidMouse2Y;
  68.  
  69. extern uchar     ciaJoy1;
  70. extern uchar     ciaJoy2;
  71. extern ciaKeyRec ciaKeyScan;
  72.  
  73. extern ushort    pcxXSize;
  74. extern ushort    pcxYSize;
  75.  
  76. void initbitmapi64k(void);
  77. void initbitmap64k(void);
  78. void initbitmap16k(void);
  79. uchar savechrsets(void);
  80. void restorechrsets(void);
  81. void draw16khelp(uchar Rect[]);
  82. void drawmenu(uchar Rect[]);
  83. void graphicsview(void);
  84. void set64kmode(void);
  85. void ilace80x50text(void);
  86. void graphics640x200(void);
  87. void pcx640x200(char * FileName);
  88. void graphics640x480(void);
  89. void pcx640x480(char * FileName);
  90.  
  91. void delay(ushort D);
  92. void planesound(void);
  93. void shotssound(void);
  94. void explodesound(void);
  95. void bombdropsound(void);
  96. void soundseq(uchar Rect[], uchar Seq);
  97. void soundwin(uchar Rect[]);
  98. void playraw(char * FileName, ulong Hz);
  99.  
  100. void controlswin(uchar Rect[]);
  101. void dispclock(void);
  102.  
  103. void init(void);
  104. void run(void);
  105. void done(void);
  106.  
  107. uchar *appChSetBufPtr; /* char set buffer pointer */
  108. uchar appColors[] =    /* colors for 64k graphics */
  109. {
  110. vdcDarkGray,
  111. vdcDarkBlue,
  112. vdcLightBlue,
  113. vdcLightBlue,
  114. vdcDarkCyan,
  115. vdcDarkCyan,
  116. vdcDarkCyan,
  117. vdcLightCyan,
  118. vdcLightCyan,
  119. vdcLightCyan,
  120. vdcMediumGray,
  121. vdcMediumGray,
  122. vdcWhite,
  123. vdcMediumGray,
  124. vdcMediumGray,
  125. vdcLightCyan,
  126. vdcLightCyan,
  127. vdcLightCyan,
  128. vdcDarkCyan,
  129. vdcDarkCyan,
  130. vdcDarkCyan,
  131. vdcLightBlue,
  132. vdcLightBlue,
  133. vdcDarkBlue,
  134. vdcDarkGray
  135. };
  136.  
  137. char *appMenuItems[6] =            /* text used by this app */
  138. {
  139. "[A] Keyboard, joy stick, paddle and mouse controls",
  140. "[B] SID sound effects",
  141. "[C] Play 4 bit digitized sound",
  142. "[D] 80 X 50 interlaced text",
  143. "[E] 640 X 200 graphics",
  144. "[F] 640 X 200 PCX image, [CONTROL] & [RUN STOP] status",
  145. };
  146.  
  147. char *app16KHelp[3] =
  148. {
  149. "DO NOT select [S] option if your C128 has a 16K VDC!",
  150. "If you have a 64K VDC use [S] to get color, text and",
  151. "interlace in graphics mode!"
  152. };
  153.  
  154. char *appSoundSeq[4] =
  155. {
  156. "Plane",
  157. "Shots",
  158. "Bomb dropping",
  159. "Explosion"
  160. };
  161.  
  162. uchar appMenuRect[]    = {10,2,69,13};  /* menu window location */
  163. uchar app16KRect[]     = {10,16,69,21}; /* 16k help window location */
  164. uchar appSoundRect[]   = {19,7,59,17};  /* sound window location */
  165. uchar appControlRect[] = {10,2,69,14};  /* control window location */
  166.  
  167. ciaTODRec appTOD = {0,0,0,0}; /* used to set tod clock to 12 am */
  168.  
  169. char  appRawName[] = {"DEMO.RAW"};
  170. ulong appHz        = 8000;
  171.  
  172. char  appPcxName1[] = {"DEMO1.PCX"};
  173. char  appPcxName2[] = {"DEMO2.PCX"};
  174.  
  175. main()
  176. {
  177.   init();
  178.   run();
  179.   done();
  180. }
  181.  
  182. void initbitmapi64k(void)
  183. {
  184.   if(is64kvdc())
  185.   {
  186.     vdcBitMapMemSize = 49152;
  187.     setcursorvdc(0,0,vdcCurNone);    /* turn cursor off */
  188.     outvdc(vdcFgBgColor,vdcBlack);   /* black screen */
  189.     attrsoffvdc();
  190.     setbitmapintvdc(appBitMapMem,appAttrMem,vdcDarkBlue,vdcBlack);
  191.     mapvdc();
  192.     clrbitmapvdc(0);
  193.   }
  194. }
  195.  
  196. void initbitmap64k(void)
  197. {
  198.   vdcBitMapMemSize = 16000;
  199.   setcursorvdc(0,0,vdcCurNone);    /* turn cursor off */
  200.   outvdc(vdcFgBgColor,vdcBlack);   /* black screen */
  201.   attrsoffvdc();                   /* disable attrs */
  202.   setbitmapvdc(appBitMapMem,appAttrMem,vdcBlack,vdcBlack); /* black fg bg */
  203.   mapvdc();                        /* set global vdc vars to reflect changes */
  204.   clrattrvdc(vdcBlack);
  205.   clrbitmapvdc(0);                 /* clear bit map */
  206.   attrsonvdc();                    /* enable attrs */
  207. }
  208.  
  209. void initbitmap16k(void)
  210. {
  211.   vdcBitMapMemSize = 16000;
  212.   setcursorvdc(0,0,vdcCurNone);    /* turn cursor off */
  213.   outvdc(vdcFgBgColor,vdcBlack);   /* black screen */
  214.   attrsoffvdc();                   /* disable attrs to work on 16k vdc */
  215.   setbitmapvdc(vdcDispMem,vdcAttrMem,vdcWhite,vdcBlack);
  216.   clrbitmapvdc(0);                 /* clear bit map */
  217. }
  218.  
  219. uchar savechrsets(void)
  220. {
  221.   if(is64kvdc())
  222.     return(1);
  223.   else
  224.   {
  225.     appChSetBufPtr = memtobufvdc(vdcCharMem,vdcCharMemSize);
  226.     if (appChSetBufPtr != NULL)
  227.       return(1);
  228.     else
  229.       return(0);
  230.   }
  231. }
  232.  
  233. void restorechrsets(void)
  234. {
  235.   if(appChSetBufPtr != NULL)
  236.   {
  237.     outvdc(vdcFgBgColor,vdcBlack); /* set foreground-background to black */
  238.     attrsoffvdc();                 /* disable attrs */
  239.     buftomemvdc(appChSetBufPtr,vdcCharMem,vdcCharMemSize);
  240.   }
  241. }
  242.  
  243. void draw16khelp(uchar Rect[])
  244. {
  245.   uchar I;
  246.  
  247.   winvdc(Rect[0],Rect[1],Rect[2],Rect[3],appMenuWinCo,"VDC Help");
  248.   for(I=0; I < 3; I++)
  249.     printstrvdc(Rect[0]+2,Rect[1]+I+2,appMenuTxtCo,app16KHelp[I]);
  250. }
  251.  
  252. void drawmenu(uchar Rect[])
  253. {
  254.   uchar I;
  255.  
  256.   outvdc(vdcFgBgColor,appMenuScrCo); /* set new screen color */
  257.   setcursorvdc(0,0,vdcCurNone);      /* turn cursor off */
  258.   clrattrvdc(appDeskCo);             /* draw desk top */
  259.   clrscrvdc(137);
  260.   filldspvdc(0,0,vdcScrHorz,32);
  261.   fillattrvdc(0,0,vdcScrHorz,appClockCo);
  262.   printstrvdc(1,0,appClockCo,"CP/M");
  263.   printstrvdc(67,0,appClockCo,"RUN");
  264.   winvdc(Rect[0],Rect[1],Rect[2],Rect[3],appMenuWinCo,"SG C Tools 1.5 Demo (C) 1993");
  265.   for(I=0; I < 6; I++)
  266.     printstrvdc(Rect[0]+2,Rect[1]+I+2,appMenuTxtCo,appMenuItems[I]);
  267.   if(is64kvdc())
  268.   {
  269.     printstrvdc(Rect[0]+2,Rect[3]-3,appMenuTxtCo,"[G] 640 X 480 graphics");
  270.     printstrvdc(Rect[0]+2,Rect[3]-2,appMenuTxtCo,"[H] 640 X 480 interlace PCX image");
  271.   }
  272.   else
  273.   {
  274.     printstrvdc(Rect[0]+2,Rect[3]-2,appMenuTxtCo,"[S] Set 64K mode");
  275.     draw16khelp(app16KRect);
  276.   }
  277.   printstrvdc(Rect[0]+2,Rect[3]-1,appMenuTxtCo,"[X] Exit to CP/M");
  278. }
  279.  
  280. void graphicsview(void) /* view graphics until key pressed */
  281. {
  282.   while (!(kbhit()));
  283.   getch();
  284.   outvdc(vdcFgBgColor,vdcBlack);
  285.   attrsoffvdc();
  286.   restorechrsets();
  287.   restorevdc();
  288.   mapvdc();
  289.   drawmenu(appMenuRect);
  290. }
  291.  
  292. void set64kmode(void)
  293. {
  294.   if(!(is64kvdc()) && appChSetBufPtr != NULL)
  295.   {
  296.     restorevdc();         /* make sure all registers are default value */
  297.     set64kvdc();          /* set 64k mode */
  298.     savevdc();            /* reflect change to reg 28 */
  299.     restorechrsets();     /* restore char sets destroyed by setting 64k mode */
  300.     free(appChSetBufPtr); /* dispose buffer */
  301.     appChSetBufPtr = NULL;
  302.     restorevdc();
  303.     mapvdc();
  304.     drawmenu(appMenuRect);
  305.   }
  306. }
  307.  
  308. void ilace80x50text(void)
  309. {
  310.   uchar I;
  311.  
  312.   outvdc(vdcFgBgColor,appIScrCo); /* set new screen color */
  313.   setdsppagevdc(vdcDispMem,vdcAttrMem << 1);
  314.   set80x50textvdc();
  315.   mapvdc();                       /* map changes */
  316.   clrattrvdc(appIDeskCo);
  317.   clrscrvdc(137);
  318.   winvdc(10,5,69,44,appIWinCo,"Interlace 80 X 50 Mode");
  319.   printstrvdc(11,43,appIWinTxtCo,
  320.   "All functions that operate in 80 X 25 work in 80 X 50 too!");
  321.   for (I = 1; I <= 36; I++)       /* scroll window */
  322.     scrollupvdc(11,7,68,43);
  323.   while (!(kbhit()));
  324.   getch();
  325.   clrattrvdc(vdcAltChrSet);
  326.   clrscrvdc(32);
  327.   restorevdc();
  328.   mapvdc();
  329.   drawmenu(appMenuRect);
  330. }
  331.  
  332. void graphics640x200(void)
  333. {
  334.   int I;
  335.   uchar X, Y;
  336.  
  337.   if(is64kvdc())
  338.   {
  339.     initbitmap64k();
  340.     for(I = 0; I <= sizeof(appColors); I++)
  341.       fillattrvdc(0,I,vdcScrHorz,appColors[I]);
  342.   }
  343.   else
  344.     initbitmap16k();
  345.   for(I = 0; I <= 639; I += 80)
  346.   {
  347.     linevdc(319,0,I,199);
  348.     linevdc(I,0,319,199);
  349.   }
  350.   for(I = 0; I <= 199; I += 32)
  351.   {
  352.     ellipsevdc(319,99,I,I >> 2);
  353.   }
  354.   if(is64kvdc())
  355.   {
  356.     printbmvdc(12,1,appGrTextCo,
  357.     "SG C Tools makes it easy to use text in GRAPHICS mode!");
  358.     printbmvdc(32,3,appGrTextCo,"Bit map colors");
  359.     for (Y = 0; Y < 16; Y++)
  360.       for (X = 0; X < 16; X++)
  361.         printbmvdc(X+31,Y+5,(Y << 4) | X,"*");
  362.   }
  363.   graphicsview();
  364. }
  365.  
  366. void pcx640x200(char * FileName)
  367. {
  368.   bdos(45,0x0FE);
  369.   if (initpcx(FileName) == pcxErrNone)
  370.   {
  371.     if (pcxXSize < 641 && pcxYSize < 201)
  372.     {
  373.       if(is64kvdc())
  374.       {
  375.         initbitmap64k();
  376.         clrattrvdc(vdcWhite);
  377.       }
  378.       else
  379.         initbitmap16k();
  380.       decodefilepcx(0,0);
  381.       donepcx();
  382.       graphicsview();
  383.     }
  384.     else
  385.       donepcx();
  386.   }
  387. }
  388.  
  389. void graphics640x480(void)
  390. {
  391.   int I;
  392.  
  393.   if(is64kvdc())
  394.   {
  395.     initbitmapi64k();
  396.     for(I = 0; I <= 639; I += 80)
  397.     {
  398.       lineivdc(319,0,I,479);
  399.       lineivdc(I,0,319,479);
  400.     }
  401.     for(I = 0; I <= 199; I += 32)
  402.     {
  403.       ellipseivdc(319,239,I,I);
  404.     }
  405.     printbmivdc(10,11,
  406.     "SG C Tools makes it easy to use text in interlace GRAPHICS too!");
  407.     graphicsview();
  408.   }
  409. }
  410.  
  411. void pcx640x480(char * FileName)
  412. {
  413.   if(is64kvdc())
  414.   {
  415.     bdos(45,0x0FE);
  416.     if (initpcx(FileName) == pcxErrNone)
  417.     {
  418.       if (pcxXSize < 641 && pcxYSize < 481)
  419.       {
  420.         initbitmapi64k();
  421.         decodefileintpcx(0,0);
  422.         donepcx();
  423.         graphicsview();
  424.       }
  425.       else
  426.         donepcx();
  427.     }
  428.   }
  429. }
  430.  
  431. void delay(ushort D) /* delay in milliseconds (1/1000 sec) */
  432. {
  433.   setintctrlcia(cia2,ciaClearIcr); /* disable all cia 2 interrupts */
  434.   settimerbcia(cia2,D,ciaCountA);  /* timer b counts timer a underflows */
  435.   settimeracia(cia2,timervalcia(1000),ciaCPUCont); /* set timer a 1/1000 sec */
  436.   while ((inp(cia2+ciaIntCtrl) & 0x02) == 0);      /* wait for count down */
  437. }
  438.  
  439. void planesound(void)
  440. {
  441.   ushort Pulse;
  442.   ushort Freq = 2047;
  443.  
  444.   volumesid(15,0);
  445.   envelopesid(sidVoice1,12,10,0,0);
  446.   attacksid(sidVoice1,sidWaveSqu);
  447.   for(Pulse = 0; Pulse < 3840; Pulse += 10)
  448.   {
  449.     pulsewavesid(sidVoice1,Pulse);
  450.     freqsid(sidVoice1,Freq);
  451.     Freq -= 5;
  452.     delay(2);
  453.   }
  454.   releasesid(sidVoice1,sidWaveSqu);
  455.   delay(6);
  456.   freqsid(sidVoice1,0);
  457. }
  458.  
  459. void shotssound(void)
  460. {
  461.   uchar I;
  462.  
  463.   volumesid(15,0);
  464.   for(I = 0; I < 20; I++)
  465.   {
  466.     envelopesid(sidVoice1,0,3,0,0);
  467.     freqsid(sidVoice1,5360);
  468.     attacksid(sidVoice1,sidWaveNoi);
  469.     delay(100);
  470.     releasesid(sidVoice1,sidWaveNoi);
  471.     delay(6);
  472.   }
  473.   freqsid(sidVoice1,0);
  474. }
  475.  
  476. void explodesound(void)
  477. {
  478.   volumesid(15,0);
  479.   envelopesid(sidVoice1,0,0,15,11);
  480.   freqsid(sidVoice1,200);
  481.   attacksid(sidVoice1,sidWaveNoi);
  482.   delay(8);
  483.   releasesid(sidVoice1,sidWaveNoi);
  484.   delay(2400);
  485.   freqsid(sidVoice1,0);
  486. }
  487.  
  488. void bombdropsound(void)
  489. {
  490.   ushort I;
  491.  
  492.   volumesid(15,0);
  493.   envelopesid(sidVoice3,13,0,15,0);
  494.   freqsid(sidVoice3,0);
  495.   attacksid(sidVoice3,sidWaveTri);
  496.   for(I = 32000; I > 200; I -= 200)
  497.   {
  498.     freqsid(sidVoice3,I);
  499.     delay(18);
  500.   }
  501.   releasesid(sidVoice3,sidWaveTri);
  502.   delay(6);
  503.   freqsid(sidVoice3,0);
  504. }
  505.  
  506. void soundseq(uchar Rect[], uchar Seq)
  507. {
  508.   scrollupvdc(Rect[0]+1,Rect[1]+2,Rect[2]-1,Rect[3]-1);
  509.   fillattrvdc(Rect[0]+2,Rect[3]-3,Rect[2]-Rect[0]-2,appSoundTxt2Co);
  510.   printstrvdc(Rect[0]+2,Rect[3]-2,appSoundTxt1Co,appSoundSeq[Seq]);
  511. }
  512.  
  513. void soundwin(uchar Rect[])
  514. {
  515.   uchar I;
  516.  
  517.   winvdc(Rect[0],Rect[1],Rect[2],Rect[3],appSoundWinCo,"SID Sound Effects");
  518.   for(I = 0; I < 4; I++)
  519.   {
  520.     soundseq(Rect,I);
  521.     switch (I)
  522.     {
  523.       case 0 :
  524.         planesound();
  525.         break;
  526.       case 1 :
  527.         shotssound();
  528.         break;
  529.       case 2 :
  530.         bombdropsound();
  531.         break;
  532.       case 3 :
  533.         explodesound();
  534.         break;
  535.     }
  536.   }
  537.   drawmenu(appMenuRect);
  538. }
  539.  
  540. void playraw(char * FileName, ulong Hz)
  541. {
  542.   uchar  *RawBufPtr;
  543.   FILE   *RawFile;
  544.   ulong  RawSize;
  545.   struct stat  StatRec;
  546.  
  547.   RawBufPtr = NULL;
  548.   bdos(45,0x0FE);
  549.   if (stat(FileName,&StatRec) == 0)
  550.     RawSize = StatRec.st_size;
  551.   else
  552.     RawSize = 0;
  553.   if (RawSize > 0)
  554.   {
  555.     RawBufPtr = (uchar *) malloc(RawSize);
  556.     if (RawBufPtr != NULL)
  557.     {
  558.       if ((RawFile = fopen(FileName,"rb")) != NULL)
  559.       {
  560.         fread(RawBufPtr,sizeof(uchar),RawSize,RawFile);
  561.         fclose(RawFile);
  562. #asm
  563.   di
  564. #endasm
  565.         setintctrlcia(cia2,ciaClearIcr);
  566.         settimeracia(cia2,timervalcia(Hz),ciaCPUCont);
  567.         playzb4sid(RawBufPtr,RawSize);
  568. #asm
  569.   ei
  570. #endasm
  571.       }
  572.       free(RawBufPtr);
  573.     }
  574.   }
  575. }
  576.  
  577. void controlswin(uchar Rect[])
  578. {
  579.   char  StrBuf[45];
  580.  
  581.   winvdc(Rect[0],Rect[1],Rect[2],Rect[3],appCtrlWinCo,"Controls");
  582.   printstrvdc(Rect[0]+2,Rect[1]+2,appCtrlTxt1Co,"Keyboard   0   1   2   3   4   5   6   7   8   9   10 ");
  583.   printstrvdc(Rect[0]+2,Rect[1]+4,appCtrlTxt1Co,"Joystick   1   2  ");
  584.   printstrvdc(Rect[0]+2,Rect[1]+6,appCtrlTxt1Co,"Paddle     1   2   3   4  ");
  585.   printstrvdc(Rect[0]+2,Rect[1]+8,appCtrlTxt1Co,"1351 Mouse X1  Y1  X2  Y2 ");
  586.   printstrvdc(Rect[0]+21,Rect[1]+11,appCtrlTxt2Co | vdcBlink,
  587.   " [RUN STOP] to exit ");
  588. #asm
  589.   di
  590. #endasm
  591.   do
  592.   {
  593.     getpotssid();  /* read controls */
  594.     getmousesid();
  595.     getjoyscia();
  596.     getkeyscia();
  597.  
  598.     sprintf(StrBuf,"%4u%4u%4u%4u%4u%4u%4u%4u%4u%4u%4u",
  599.     ciaKeyScan[0],ciaKeyScan[1],ciaKeyScan[2],ciaKeyScan[3],
  600.     ciaKeyScan[4],ciaKeyScan[5],ciaKeyScan[6],ciaKeyScan[7],
  601.     ciaKeyScan[8],ciaKeyScan[9],ciaKeyScan[10]);
  602.     printstrvdc(Rect[0]+12,Rect[1]+3,appCtrlTxt2Co,StrBuf);
  603.  
  604.     sprintf(StrBuf,"%4u%4u",ciaJoy1,ciaJoy2);
  605.     printstrvdc(Rect[0]+12,Rect[1]+5,appCtrlTxt2Co,StrBuf);
  606.  
  607.     sprintf(StrBuf,"%4u%4u%4u%4u",sidPot1X,sidPot1Y,sidPot2X,sidPot2Y);
  608.     printstrvdc(Rect[0]+12,Rect[1]+7,appCtrlTxt2Co,StrBuf);
  609.  
  610.     sprintf(StrBuf,"%4u%4u%4u%4u",sidMouse1X,sidMouse1Y,sidMouse2X,sidMouse2Y);
  611.     printstrvdc(Rect[0]+12,Rect[1]+9,appCtrlTxt2Co,StrBuf);
  612.   }
  613.   while(ciaKeyScan[7] != 127);
  614. #asm
  615.   ei
  616. #endasm
  617.   drawmenu(appMenuRect);
  618. }
  619.  
  620. void dispclock(void)
  621. {
  622.   ciaTODStr TODStr;
  623.  
  624.   gettodcia(cia1,appTOD);
  625.   todstrcia(appTOD,TODStr);
  626.   printstrvdc(6,0,appClockCo,TODStr);
  627.   gettodcia(cia2,appTOD);
  628.   todstrcia(appTOD,TODStr);
  629.   TODStr[8] = 0;                          /* get rid of am/pm extension */
  630.   printstrvdc(71,0,appClockCo,TODStr);
  631. }
  632.  
  633. void init(void)
  634. {
  635.   settodcia(cia2,appTOD);
  636.   clearsid();
  637.   savevdc();
  638.   mapvdc();
  639.   appChSetBufPtr = NULL;
  640. }
  641.  
  642. void run(void)
  643. {
  644.   char  InKey;
  645.  
  646.   winvdc(21,5,58,10,vdcAltChrSet+vdcDarkGreen,"Info");
  647.   printstrvdc(23,7,vdcAltChrSet+vdcBlink+vdcLightGreen,
  648.   "Saving character sets to buffer");
  649.   if(savechrsets())     /* check if vdc in 16k mode */
  650.   {
  651.     drawmenu(appMenuRect);
  652.     do
  653.     {
  654.       while (!(kbhit()))
  655.         dispclock();
  656.       InKey = toupper(getch());
  657.       switch (InKey)
  658.       {
  659.         case 'A':
  660.           controlswin(appControlRect);
  661.           break;
  662.         case 'B':
  663.           soundwin(appSoundRect);
  664.           break;
  665.         case 'C':
  666.           playraw(appRawName,appHz);
  667.           break;
  668.         case 'D':
  669.           ilace80x50text();
  670.           break;
  671.         case 'E':
  672.           graphics640x200();
  673.           break;
  674.         case 'F':
  675.           pcx640x200(appPcxName1);
  676.           break;
  677.         case 'G':
  678.           graphics640x480();
  679.           break;
  680.         case 'H':
  681.           pcx640x480(appPcxName2);
  682.           break;
  683.         case 'S':
  684.           set64kmode();
  685.           break;
  686.       }
  687.     }
  688.     while (InKey != 'X');
  689.   }
  690. }
  691.  
  692. void done(void)
  693. {
  694.   clearsid();
  695.   if(appChSetBufPtr != NULL)
  696.     free(appChSetBufPtr);
  697.   restorevdc();     /* restore registers saved by savevdc() */
  698.   putchar(0x1A);    /* adm-3a clear-home cursor */
  699. }
  700.